from common.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy


class SellingStocks(BasePage):
    # 点击头像
    headSculpture_loc = (AppiumBy.ID, 'com.jhss.youguu:id/head_pic')
    # 登录按钮
    loginBtn_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_login')
    # 账号密码登录
    zhmm_loc = (AppiumBy.ID, 'com.jhss.youguu:id/tv_change_login_type')
    # 输入账号
    zh_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_username')
    # 输入密码
    mm_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_password')
    # 点击登录
    clicklogin_loc = (AppiumBy.ID, 'com.jhss.youguu:id/bt_login')
    # 点击回退
    back_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_back')
    # 模拟炒股
    mncg_loc = (AppiumBy.XPATH, '//android.widget.ImageView[@bounds="[411,1491][489,1569]"]')
    # 点击卖出
    selling_loc = (AppiumBy.ID,'com.jhss.youguu:id/btn_sell')
    # 选择持仓股票
    HoldingStocks_loc=(AppiumBy.XPATH,'//android.widget.LinearLayout[@bounds="[60,328][320,416]"]')
    # 输入卖出数量
    salesQuantity_loc=(AppiumBy.ID,'com.jhss.youguu:id/et_stock_amount')
    # 点击卖出
    clickSelling_loc=(AppiumBy.XPATH,'//android.widget.TextView[@bounds="[24,888][652,968]"]')
    # 点击确定
    determine_loc=(AppiumBy.ID,'com.jhss.youguu:id/btn_confirm')
    # 点击撤单
    cancelorder_loc=(AppiumBy.ID,'com.jhss.youguu:id/btn_revoke')
    # 获取元素
    getEle_loc=(AppiumBy.XPATH,'//android.widget.TextView[@text="焦作万方"]')

    def sellingStocks(self, name, pwd,num):
        self.click_ele(self.headSculpture_loc)
        self.click_ele(self.loginBtn_loc)
        self.click_ele(self.zhmm_loc)
        self.send_keys(self.zh_loc, name)
        self.send_keys(self.mm_loc, pwd)
        self.click_ele(self.clicklogin_loc)
        # 点击回退
        self.click_ele(self.back_loc)
        # 模拟炒股
        self.click_ele(self.mncg_loc)
        self.click_ele(self.selling_loc)
        self.click_ele(self.HoldingStocks_loc)
        self.send_keys(self.salesQuantity_loc,num)
        self.click_ele(self.clickSelling_loc)
        self.click_ele(self.determine_loc)
        # 点击撤单
        self.click_ele(self.cancelorder_loc)

